package com.jd.sunny.java;

/**
 * @Description: TestArray
 * @author:孙林
 * @since:12-11-27下午5:11
 * @version:1.0.0
 */

import java.util.Arrays;

/**
 * 数组一旦创建，就无法改变其大小
 */
public class TestArray {

    public static void main(String[] args){
//        testArrayIndex();
//        testArrayCopy();
        testArraySort();
    }

    /**
     * Test ArrayIndexOutOfBoundsException
     */
    public static void testArrayIndex(){
        int[] number = {1,2,3,4,5,6,7,8};
        System.out.println(number[8]);
    }

    /**
     * copy array
     */
    public static void testArrayCopy(){
        int[] number = {1,2,3,4,5,6,7,8};
        int [] newNumber1 = Arrays.copyOf(number,number.length);
        int [] newNumber2 = Arrays.copyOf(number,number.length - 2);
        System.out.println(Arrays.toString(newNumber1));
        System.out.println(Arrays.toString(newNumber2));
    }

    /**
     * test array sort,from small to large
     */
    public static void testArraySort(){
        int[] number = {1,2,11,90,5,67,33,17};
        Arrays.sort(number);
        System.out.println(Arrays.toString(number));
    }

}
